
Dim 大漠路径
大漠路径 = "D:\fengyin\"

//Dim 大漠路径
//大漠路径 = "D:\boot\医生"
Plugin.jd.CreateFolder 大漠路径
PutAttachment 大漠路径, "dm.dll"
PutAttachment ".\plugin", "DmReg.dll"
PutAttachment ".\plugin", "jd.dll"
Plugin.jd.DmRegEx "DmReg", "SetDllPathA", 大漠路径 & "\dm.dll", 0
' 版本判断
set dm = createobject("dm.dmsoft")
ver = dm.Ver()
If ver <> 7.2211 Then 
    TracePrint ver
    messagebox "安装失败"
    ExitScript
End If
' 注册是否成功
res = dm.Reg("pangpangabccf5dcdcd4a19721bfaa6881f0aef592c", "nbJZ")
If res <> 1 Then 
    TracePrint "注册码无效,返回:" & res
Else 
    TracePrint "成功"
End If
dm.setpath "D:\fengyin\"
res1 = dm.SetDict(0, "zilib.txt")

hwnd = dm.GetMousePointWindow()
dm_ret = dm.BindWindowEx(hwnd,"dx.graphic.3d.10plus","dx.mouse.position.lock.api|dx.mouse.api|dx.mouse.cursor","dx.keypad.api","dx.public.active.api|dx.public.hide.dll|dx.public.graphic.protect|dx.public.down.cpu",101)
// 锁定后台禁止外部输入  后台才使用
//dm.LockInput 1
If dm_ret = 1 Then 
messagebox "绑定后台成功"
	Else 
	messagebox "绑定后台失败"
End If

// 释放
Sub OnScriptExit()
    dm_ret = dm.UnBindWindow() 
End Sub

dm.setpath "D:\fengyin\"
res1 = dm.SetDict(0, "zilib.txt")


// 入口
Call main
Function main()
    Do
        call dm.FindStrFast(0,0,2000,2000,"55秒","a5cbf7-000000",0.1,intX,intY)
        If intX >= 0 and intY >= 0 Then 
            // 识别到读秒 准备运行
            Call run
        Else 
            // 有时候会没有读秒也在等待中
            res_pkg = isPackageOpen()
            If res_pkg = 1 Then 
                Call run
            End If
        End If
        Delay 500
    Loop
End Function
// 运行
Function run()
    TracePrint "开始运行"
    // 关闭自动战斗
    ' call isAutoF

    // 背包是否打开
    res_pkg = isPackageOpen()
    If res_pkg <> 1 Then 
        // 打开背包
        res_open = doOpenPkg()
    Else
        ka = "i_1.bmp"
        // 点击卡片
        res_ka = clickKa(ka)
        Delay 300
        If res_ka = 1 Then 
            // 点击使用
            res_use = clickUse()
            Delay 300
            If res_use = 1 Then 
                Call clickMonster2
                Delay 300
                Call petDefer
            End If
        End If
    End If
End Function
// 点击卡牌
Function clickKa(ka)
    dm_ret = dm.FindPicEx(0,0,2000,2000, ka, "503050", 0.9, 0)
    TracePrint dm_ret
    If len(dm_ret) > 0 Then
        m_data = split(dm_ret, "|")
        //0,1112,253|0,1112,339|0,771,424|0,856,424
        // 只取第一个
        temp = m_data(0)
        坐标 = split(temp, ",")
        dm.MoveTo 坐标(1), 坐标(2)
        Delay 300
        dm.LeftClick 
        clickKa = 1
    Else 
    	// todo 卡牌烧完
        clickKa = 0
    End If
 
End Function

Function isAutoF()
    dm_ret = dm.FindMultiColor(0,0,2000,2000,"4d454d","-12|12|fed943,20|12|ff8935,-38|0|bae9f7,48|13|b4e4f6,12|-39|c2eafb",0.9,3,intX,intY)
    If intX >= 0 and intY >= 0 Then 
        dm.MoveTo intX, intY
        Delay 300
        dm.LeftClick 
        TracePrint "改成非自动"
        isAutoF = 0
    End If
End Function
// 点击使用按钮
Function clickUse()
    Dim state
    state = 0
    dm_ret = dm.FindStrFast(0,0,2000,2000,"使用","0.0.100-70.20.50",0.9,intX,intY)
    If intX >= 0 and intY >= 0 Then 
        TracePrint " 发现使用按钮:"
        dm.MoveTo intX, intY
        Delay 300
        dm.LeftClick 
        TracePrint " 点击使用按钮:"
        Delay 200
        clickUse = 1
    Else
    clickUse = 0
    End If

End Function
// 宠物防御
Function petDefer()

    // 这个有时候找不到,  模糊度降低点
    dm_ret = dm.FindStrFast(0,0,2000,2000,"防御","0.0.100-70.28.37",0.8,intX,intY)
    If intX >= 0 and intY >= 0 Then 
        TracePrint " 发现宠物防御按钮:"
        dm.MoveTo intX, intY-50
        Delay 300 
        dm.LeftClick 
        TracePrint "点击宠物防御按钮:"
        Delay 200
    Else 
        TracePrint "没发现宠物防御按钮,使用多点找图.."
        dm_ret = dm.FindMultiColor(0,0,2000,2000,"805b45","-16|20|876d54,19|38|915a30,2|41|8c542a,-25|-8|5b381e",0.9,3,intX,intY)
        If intX >= 0 and intY >= 0 Then 
            dm.MoveTo intX, intY
            Delay 300
            dm.LeftClick 
        else 
            TracePrint "多点找图也失败了..,进入新循环"
        End If
    End If
   
End Function
// 背包是否打开
Function isPackageOpen()

    dm_ret = dm.FindStrFast(0, 0, 2000, 2000, "装备", "0.0.100-70.20.50", 0.9, intX, intY)
    If intX >= 0 and intY >= 0 Then 
        TracePrint " 背包打开了:"
        isPackageOpen = 1
    else 
        isPackageOpen = 0
    End If

End Function
// 打开背包 
Function doOpenPkg()

    dm_ret = dm.FindMultiColor(0,0,2000,2000,"bd6234","-10|8|5e56de,-5|-5|493535,21|-10|eaead0,18|-4|a29ea4",0.9,3,intX,intY)
    If intX >= 0 and intY >= 0 Then 
        dm.MoveTo intX, intY
        TracePrint "发现背包按钮" & i
        Delay 300
        dm.LeftClick 
        doOpenPkg = 1
    else 
        doOpenPkg = 0
    End If

End Function
// 点击怪物(怪物头像)
Function clickMonster2()
    Dim 主颜色(8)
    Dim 多点色(8)
    //////////////// 翠绿菇
    // 蹲着
    主颜色(0) = "7dd158"
    多点色(0) = "-7|4|ffff5a,1|10|ffff7e,8|4|7fcf59,-1|6|aaf785,-2|21|91d954,15|11|5eb14d,-7|12|a5f785"
    // 站着
    主颜色(1) = "acef8a"
    多点色(1) = "-10|0|fefe5c,5|-3|6fc452,1|4|95e178,-9|6|9bea7d,14|3|589656,-2|8|e4fd6a,-2|-5|74c75a"
    // 跳
    主颜色(2) = "dfd3b2"
    多点色(2) = "-4|-3|f5e3b3,4|1|acab8c,-4|5|efdebd,-8|-13|ffff60,1|-8|222222,-5|-18|95e178,4|-20|659958"
    //////////////// 树精
    主颜色(3) = "d95c33"
    多点色(3) = "7|-33|fafafa,-38|-72|64ac54"
    // 树精叶子2
    主颜色(4) = "e96d1d"
    多点色(4) = "-30|-56|5ea858,-32|-55|7dc963,-14|-50|7a3915"
    
    // 偷袭头像
    //////////////// 翠绿菇
    // 站立
    主颜色(5) = "8dde5d"
    多点色(6) = "-11|5|ffff5d,4|-4|c6af6f,9|7|6ec054,0|19|bdb5a0"
    // 跳跃
    主颜色(6) = "96e27a"
    多点色(6) = "7|-1|bca86a,-1|11|ffff6b,-3|-5|ffff7c,-10|17|d8d7b3"
    // 低头
    主颜色(7) = "88d154"
    多点色(7) = "10|-1|a19359,-8|0|f9ed6c,-2|15|f4e1b8,6|18|bbbc9e"
    //////////////// 树精
    // 叶子一
    主颜色(7) = "bc5816"
    多点色(7) = "32|-72|478940,37|-72|3d7c3e,11|-21|5f261b,-7|-94|bbbc9e"
    // 叶子二
    主颜色(7) = "aa5120"
    多点色(7) = "29|-56|2c5c2c,33|-54|2c6331,14|6|472015,-6|-21|7b3f1a"
    
    Do 
        For i = 0 To UBound(主颜色)
            dm_ret = dm.FindMultiColor(0,0,2000,2000,主颜色(i),多点色(i),0.9,0,intX,intY)
            If intX >= 0 and intY >= 0 Then 
                dm.MoveTo intX, intY
                TracePrint "发现怪物坐标" & i
                Delay 300
                dm.LeftClick 
                Exit Do
                // 好像不用Exit For 也会终止
                Exit For
            Else 
                TracePrint "没有发现怪物坐标"
            End If
            Delay 100
        Next
        Delay 100
    Loop
End Function
